package com.example.demo.controller;

import com.example.demo.pojo.Link;
import com.example.demo.service.LinkService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags="链接管理系统")
public class LinkController {
    @Autowired
    private LinkService linkService;

    @ApiOperation("链接新增")
    @PostMapping("/link/add")
    public String add(Link link){
        linkService.save(link);
        return "数据新增成功";
    }
    
    @GetMapping("/link/selectByPage")
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name="size",value = "页面大小",required = true),
            @ApiImplicitParam(name = "page",value = "页码",required = true)
    })
    public PageInfo seleceByPage(int size, int page){
        PageInfo pageInfo=linkService.findByPage(size,page);
        return pageInfo;
    }

    @GetMapping("/link/deleteConcrete")
    @ApiOperation("具体的进行删除")
    public String deleteConcrete(Link link){
        linkService.delete(link);
        return "删除成功";
    }

    @GetMapping("/link/deleteById")
    @ApiOperation("根据ID进行删除")
    @ApiImplicitParam(name = "id",value ="链接编码",required = true)
    public String deleteById(int id){
        linkService.delete1(id);
        return "删除成功";
    }

    @PostMapping("/link/select")
    @ApiOperation("根据ID进行查询")
    @ApiImplicitParam(name = "id",value = "链接编号",required = true)
    public Link select(int id){
        Link link=linkService.select(id);
        return link;
    }

    @PostMapping("/link/update")
    @ApiOperation("更新操作")
    public String update(Link link){
        linkService.update(link);
        return "更新成功";
    }
    
    @PostMapping("/link/batchDelete")
    @ApiOperation("批量删除")
    @ApiImplicitParam(name = "ids",value = "批量ID，每个ID用英文状态逗号分开",required = true)
    public String batchDelete(int[] ids){
       for(int id:ids){
            linkService.delete1(id);
        }
        return "删除成功";
    }

}
